package dp.mobile.sbm.view;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import dp.mobile.sbm.R;
import dp.mobile.sbm.model.News;

public class NewsAdapter extends ArrayAdapter<News> {

	public NewsAdapter(Context context, int textViewResourceId,List<News> objects) {
		super(context, textViewResourceId, objects);
		
		//Save
		mNewsList = objects;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		//Prepare variable
		View NewsView 	= convertView;
		News Data		= mNewsList.get(position);
		
		//If no view
		if (NewsView == null) {
			//Inflate
			LayoutInflater Inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			NewsView = Inflater.inflate(R.layout.news_item, null);
		}		
		
		//If data exist
		if (NewsView != null && Data != null) {
			//Get labels
			TextView LabelTitle		= (TextView) NewsView.findViewById(R.id.news_item_title);
			TextView LabelContent 	= (TextView) NewsView.findViewById(R.id.news_item_content);
			
			//If label exist
			if (LabelTitle != null) 	LabelTitle.setText(Data.getTitle());
			if (LabelContent != null) 	LabelContent.setText(Data.getContent());
		}
		
		//Return the view
		return NewsView;
	}
	
	protected List<News> mNewsList;
}
